{extend name="common/base"/}
{block name="style"}
<link rel="stylesheet" href="{__CSS__}/user.css?v={:get_system_config('web','version')}" media="all">
{/block}
<!-- 主体 -->
{block name="body"}
{include file="common/header" /}
<div class="user">
	<div class="user-home"><a href="/">首页</a> - 个人中心</div>
	<div class="user-box clearfix">
		<div class="l user-menu">
			{include file="common/usermenu" /}
		</div>
		<div class="r user-right">
			<div class="user-detail">
				<div class="user-detail-h3">修改密码</div>
				<form id="userPwd" autocomplete="off">
				<table class="user-detail-table">
					<tr>
						<td class="td-gay" width="12%">真实姓名</td>
						<td width="38%">
							<input type="hidden" name="id" value="{$userInfo.id}">
																
							<input type="text" name="name" value="{$userInfo.name}">
						</td>
						<td class="td-gay"  colspan="2"></td>

					</tr>

					<tr>
						<td class="td-gay">原密码</td>
						<td>
							<input type="password" name="pwd" value="" style="width:99%;"
								placeholder="请输入您的原密码" />
						</td>
						<td  colspan="2"> 请输入原密码 </td>
						
					</tr>
					<tr>
						<td class="td-gay">新密码</td>
						<td>
							<input type="password" name="newpwd" value="" style="width:99%;"
								placeholder="请输入您的新密码" />
						</td>
						<td colspan="2">请输入您的新密码 </td>

					</tr>
					<tr>
						<td class="td-gay">确认密码</td>
						<td>
							<input type="password" name="newpwd2" value="" style="width:99%;"
								placeholder="请输入您的新密码" />
						</td>
						<td  colspan="2"> 请再次输入您的新密码</td>

					</tr>
		
				</table>
				</form>
				<div class="user-detail-edit">
					<span class="edit-save">保存</span>
					<span class="edit-cancel">取消</span>
				</div>
			</div>
		</div>
	</div>
</div>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script language="javascript" src="{__JS__}/laydate/laydate.js"></script>
<script>





	//取消
	$('.edit-cancel').on('click', function () {
		window.location.href = '/home/user/password';
	});

	//保存用户信息
	$('.edit-save').on('click', function () {
		var pwd = $('[name="pwd"]').val(),
			newpwd = $('[name="newpwd"]').val(),
			newpwd2 = $('[name="newpwd2"]').val();
			
		if (pwd == '') {
			layer.msg('原密码不能为空');
			return;
		}
		if (newpwd == '' ) {
			layer.msg('新密码不能为空');
			return;
		}
		if (newpwd != newpwd2) {
			layer.msg('密码确认不正确');
			return;
		}
		$.ajax({
			url: "/home/user/password_submit",
			data: $('#userPwd').serialize(),
			type: 'post',
			async: true,
			success: function (res) {
				if(res.code === 0){
					layer.msg(res.msg, { icon: 1 });
					setTimeout(function () {
						window.location.href = "{:url('/home/user/index')}";
					}, 1500);
				}else{
					layer.msg(res.msg, { icon: 0 });
					
				}
				
				
			}
		})
	});
</script>
{/block}
<!-- /脚本 -->